package com.app.Tree;

import java.util.ArrayList;

import com.app.Activity.MESApplication;

import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.drawable.shapes.RoundRectShape;
import android.util.Log;
import app.com.ModuleRole.R;

public class TreeMenu {
	final public static int ADD=1;
	final public static int REMOVE=2;
	final public static int EDIT=3;
	final public static int NOTE=4;
	final public static int DETAILS=5;
	final public static int ARRANGE=6;
	final public static int ZOOM_IN=7;
	final public static int ZOOM_OUT=8;
	final public static float ITEM_HEIGHT=40;
	public static float SPACE=10;
	float width=120;
	float heigh=ITEM_HEIGHT;
	
	 float x=10;
	 float y=10;
	private boolean showed; 
	ArrayList<MenuItem> items;
	public void onDraw(Canvas canvas){		
//		RectF rect=new RectF(this.x,this.y,this.x+this.width,this.y+this.heigh);
//		Paint p=new Paint();
//		p.setARGB(100, 129, 28, 59);
//		canvas.drawRect(rect, p);
		if(!showed)
			return;
		for(MenuItem item:items){
			item.onDraw(canvas);			
		}		
	}
	public void setPosition(float x, float y){
		this.x=x;
		this.y=y;
	}
	public int getCollisionItemId(float x, float y){
		int rs=-1;
		if(!this.showed)
			return rs;
		for(MenuItem item:items){
			if(item.isConllison(x, y)){
				return item.getId();
			}
		}
		return rs;
	}
	public void createEditMenu(){
		
		Bitmap add, remove,edit,note,details,arrange;
		Resources resources=MESApplication.getAppContext().getResources();
		
		add=BitmapFactory.decodeResource(resources, R.drawable.plus);
		remove=BitmapFactory.decodeResource(resources, R.drawable.minus);
		edit=BitmapFactory.decodeResource(resources, R.drawable.update);
		note=BitmapFactory.decodeResource(resources, R.drawable.note);
		details=BitmapFactory.decodeResource(resources, R.drawable.details);
		arrange=BitmapFactory.decodeResource(resources, R.drawable.arrange);
		
		items=new ArrayList<MenuItem>();
		MenuItem mnuAdd,mnuRemove, mnuEdit, mnuNote, mnuDetails, mnuArrange;
		mnuAdd=new MenuItem(ADD, x, y, add);
		mnuRemove=new MenuItem(REMOVE, x+32, y, remove);
		mnuEdit=new MenuItem(EDIT, x+64, y, edit);
		mnuNote=new MenuItem(NOTE, x+96, y, note);
		mnuDetails=new MenuItem(DETAILS, x+128, y, details);
		mnuArrange=new MenuItem(ARRANGE, x+160,y, arrange);
		items.add(mnuAdd);
		items.add(mnuRemove);
		items.add(mnuEdit);
		items.add(mnuNote);
		items.add(mnuDetails);		
		items.add(mnuArrange);
		resizeItem();
	}
	public void createZoomMenu(){
		Resources resources=MESApplication.getAppContext().getResources();
		Bitmap bmZoomIn, bmZoomOut;
		MenuItem mnuZoomIn, mnuZoomOut;
		
		bmZoomIn=BitmapFactory.decodeResource(resources, R.drawable.zoom_in);
		bmZoomOut=BitmapFactory.decodeResource(resources, R.drawable.zoom_out);
		
		
		mnuZoomIn=new MenuItem(ZOOM_IN, x, y, bmZoomIn);
		mnuZoomOut=new MenuItem(ZOOM_OUT, x, y, bmZoomOut);
		items=new ArrayList<MenuItem>();
		items.add(mnuZoomIn);
		items.add(mnuZoomOut);
		resizeItem();		
	}
	private void resizeItem(){
		this.width=(ITEM_HEIGHT+SPACE)*this.items.size();
		for(int i=0;i<this.items.size();i++){
			this.items.get(i).setX(this.x+(ITEM_HEIGHT+SPACE)*i);
		}
	}
	public boolean isShowed() {
		return showed;
	}
	public void setShowed(boolean showed) {
		this.showed = showed;
	}
	public float getX() {
		return x;
	}
	public void setX(float x) {
		this.x = x;
	}
	public float getY() {
		return y;
	}
	public void setY(float y) {
		this.y = y;
	}
	
}
